<?php
namespace App\Common\Cla\Weixin\OfficialAccount;

use App\Common as com;

class OfConfig extends com\Cla\ClaBase {

	/**
	 * @var \EasyWeChat\OfficialAccount\Application
	 */
	private \EasyWeChat\OfficialAccount\Application $easyObj;

	/**
	 * @param array $easyConfig
	 */
	public function __construct( private array $easyConfig ) {
		parent::__construct();
	}

	/**
	 * @return array
	 */
	public function getEasyConfig(  ):array {
		return $this->easyConfig;
	}

	/**
	 * 获取微信对象
	 * @return \EasyWeChat\OfficialAccount\Application
	 */
	public function getEasyObj(  ):\EasyWeChat\OfficialAccount\Application {
		if( ! isset( $this->easyObj ) ){
			$this->easyObj = \EasyWeChat\Factory::officialAccount( $this->getEasyConfig() );
		}
		//
		return $this->easyObj;
	}

	// ===============================
	//
	//
	// 下面为静态方法
	//
	//
	// ===============================

	/**
	 * @return $this
	 * @throws
	 */
	public static function makeAsXXXOfficialAccount(  ):self {
		$config = com\Lib\Hyperf::configOrFail( 'web.easyWechat.xxx.officialAccount' );
		//
		return self::make( $config );
	}

}
